#############################
###   GENERATE FIGURE 1   ###
###          ESS          ###
#############################
source("coefplot.stacked.R") ## this loads the plotting function

### you need to install the package haven to read the coefficient matrix
library(haven)

# Import value coefficients

cf <- read_stata("figure1_ess.dta")

cf <- data.frame(cf)

# Define names

namez <- c("Liberal values",
           "Tradition",
           "Safety",
           "Immig. (culture)",
           "Immig. (economy)"
)

# Let's flip over the observations

namez <- namez[length(namez):1]

# Generate graph

pdf(paste0("figure1_ess", ".pdf"), width=4.5, height=6.5)

f2 <- stackplot(cf[,2:7], longnames=FALSE,return.position = TRUE,center.labels = TRUE, fifty=FALSE,
                main.label = "ESS",
                cex.pts = 1.25, box=TRUE, symmetric = FALSE, offset=-.041, cex.var=1  , pch.type = c(rep(c( 16,16,16),4),16,16,16))

points(.36,5.2, pch=16, cex=1.1)
text(.36, 5.2, "Import shock (IV)", cex=0.8, pos=4)

text(-.0, 5.5, "Liberal values", cex=0.9, pos=4)
text(-.0, 4.5, "Tradition", cex=0.9, pos=4)
text(-.0, 3.5, "Safety", cex=0.9, pos=4)
text(-.0, 2.5, "Immigration (culture)", cex=0.9, pos=4)
text(-.0, 1.5, "Immigration (economy)", cex=0.9, pos=4)


dev.off()

